﻿$.MGJ.ProductAllot = [];

(function () {
    var _this = $.MGJ.ProductAllot;
    $.extend($.MGJ.ProductAllot, {
        // 显示详细数据
        Dialog_AllotShowDataObj: null,
        Dialog_AllotShowData: function (obj) {
            var id = $(obj).attr("ID");
            this.Dialog_AllotShowDataObj = $.L.dialog({
                url: ACTION_URL("AllotShowData", "FleeGoods") + "?id=" + id,
                title: "详细数据",
                width: 1100,
                height: 'auto',
                buttons: {
                    "button_cancel": {
                        type: 'primary',
                        text: '返回',
                        click: 'MODALMISS'
                    }
                },
            });
        },
        // 产品调拨信息
        Dialog_AllotInfoObj: null,
        Dialog_AllotInfo: function () {
            this.Dialog_AllotInfoObj = $.L.dialog({
                url: ACTION_URL("AllotInfo", "FleeGoods"),
                title: "输入物流码信息",
                width: 800,
                height: 'auto',
            });
        },

        // 调拨编辑
        Dialog_EditAllotObj: null,
        Dialog_EditAllot: function (obj) {
            var TheText;
            var index_1 = $("#tableList_right tr").index($(obj).parent().parent());
            $("#tableList tr").each(function () {
                var index_2 = $(this).index();
                if (index_2 == index_1) {
                    TheText = $(this).find(".StatusText").text();
                }
            })
            var id = $(obj).attr("ID");
            if (TheText == "待编辑" || TheText == undefined) {
                this.Dialog_EditAllotObj = $.L.dialog({
                    url: ACTION_URL("EditAllot", "FleeGoods") + "?id=" + id,
                    title: "编辑调拨信息",
                    width: 800,
                    height: 'auto',
                    async: true,
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '保存',
                            click: function () {
                                if ($("#ProductName").val() != "") {
                                    _this.Ajax_SaveDate();
                                } else {
                                    $.L.msgError("产品不存在")
                                }
                            }
                        },
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditAllotObj.close();
                                _this.Ajax_AllotPageList(1);
                            }
                        }
                    },
                });
            } else {
                this.Dialog_EditAllotObj = $.L.dialog({
                    url: ACTION_URL("EditAllot", "FleeGoods") + "?id=" + id,
                    title: "编辑调拨信息",
                    width: 800,
                    height: 'auto',
                    async: true,
                    buttons: {
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditAllotObj.close();
                                _this.Ajax_AllotPageList(1);
                            }
                        }
                    },
                });
            }
        },

    });
})(jQuery);
(function () {
    var _this = $.MGJ.ProductAllot;
    $.extend($.MGJ.ProductAllot, {


    });
})(jQuery);
(function () {
    var _index = 1;
    var _this = $.MGJ.ProductAllot;
    $.extend($.MGJ.ProductAllot, {
        //分页查询
        //Ajax_AllotPageList: function (pageIndex) {
        //    _index = pageIndex;
        //    var key = $("#Key").val();

        //    $.L.ajaxHandle({
        //        url: ACTION_URL("AlloPageList", "FleeGoods"),
        //        data: {
        //            key: key,
        //            pageIndex: pageIndex,
        //            pageSize: 10

        //        },
        //        success: function (response) {
        //            $("#tableList").L_bindingDataList(response);

        //        }
        //    });
        //},
        //多条件查询
        Ajax_AllotPageList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#Key").val());
            $.L.ajaxHandle({
                url: ACTION_URL("AlloPageList", "FleeGoods") + "?pageindex=" + pageIndex,
                data: $("#SearchForm").serialize(),
                success: function (response) {
                    $("#tableList").L_bindingDataList(response);
                    $("#tableList_right").L_bindingDataList(response);
                    for (var i = 0; i < response.PageData.length; i++) {
                        var TheText = response.PageData[i].statusText
                        if (TheText == "待编辑" || TheText == "") {
                            $(".IfTextBtn").eq(i).text("编辑")
                        } else {
                            //  $(".IfTextBtn").eq(i).text("查看")
                            $(".IfTextBtn").eq(i).attr("style", "visibility:hidden;")
                        }
                    }


                }
            });
        },
        //填写物流码
        Ajax_LittleAllotion: function () {
            var BoxCodes = $("#BoxCodes").val();
            $.L.ajaxHandle({
                url: ACTION_URL("AlloLittleCode", "FleeGoods"),
                data: {
                    BoxCode: BoxCodes,
                },
                success: function (response) {                 
                   var data = eval('(' + response + ')');
                    if (data.id > 0) {
                        _this.Dialog_AllotInfoObj.close();
                        $.MGJ.ProductAllot.Dialog_EditAllot({ 'ID': data.id });
                    } else {
                        $.L.msgError(data.text);
                    }
                }
            });
        },
        //编辑
        Ajax_SaveDate: function () {
            $.L.ajaxHandle({
                url: ACTION_URL("AllotSaveDate", "FleeGoods"),
                data: $("#form").serialize(),
                success: function (r) {
                    if (r <= 0) $.L.msgSuccess("提交失败！");
                    else {
                        $.L.msgSuccess("提交成功！");
                        _this.Dialog_EditAllotObj.close();
                        _this.Ajax_AllotPageList(1);
                    }
                   
                }
            });
        },

        //删除
        Ajax_Del: function (obj) {
            $.L.msgConfirm("确认删除该记录?", function () {
     var ID = $(obj).attr("ID");

            $.L.ajaxHandle({
                url: ACTION_URL("DelAllocation", "FleeGoods"),
                data: {
                    id: ID,
                },
                success: function (r) {
                    // $("#tableList").L_bindingDataList(response);
                    if (r > 0) {
                        $.L.msgSuccess("删除成功！");
                        _this.Ajax_AllotPageList(_index);
                    }
                }
            });
            })
       
        },
    });
})(jQuery);